﻿using Pipes.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace Pipes.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for XmlElementReaderTest and is intended
    ///to contain all XmlElementReaderTest Unit Tests
    ///</summary>
  [TestClass()]
  public class XmlElementReaderTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion


    /// <summary>
    ///A test for GetEnumerator
    ///</summary>
    [TestMethod()]
    public void GetEnumeratorTest()
    {
      var expected = @"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""><SOAP-ENV:Body><Result><Item type=""Concern"" typeId=""F1D2DE3EAFAB4B2B935D7061C49DF35B"" id=""CE792EFD900A42A4A4B0EF5BF2FA8AB7""><classification>Production/Production Line</classification><id keyed_name=""C:059303"" type=""Concern"">CE792EFD900A42A4A4B0EF5BF2FA8AB7</id><mfg_line keyed_name=""OEC500-2"" type=""Manufacturing Entity""><Item type=""Manufacturing Entity"" typeId=""A46CE867356D43C8A3BC7FFC83FC97E0"" id=""2A82E407803C414582325950B686EBE0""><id keyed_name=""OEC500-2"" type=""Manufacturing Entity"">2A82E407803C414582325950B686EBE0</id><itemtype>A46CE867356D43C8A3BC7FFC83FC97E0</itemtype></Item></mfg_line><item_nbr_base keyed_name=""348-0534-000"" type=""Part"">C0F27B3A061346BDB2765F78C66450F4</item_nbr_base></Item><Item type=""Concern"" typeId=""F1D2DE3EAFAB4B2B935D7061C49DF35B"" id=""16351507B0CD4DFA98F7AE863F471FA5""><classification>Production/Production Line</classification><id keyed_name=""C:059304"" type=""Concern"">16351507B0CD4DFA98F7AE863F471FA5</id><mfg_line keyed_name=""SA006"" type=""Manufacturing Entity""><Item type=""Manufacturing Entity"" typeId=""A46CE867356D43C8A3BC7FFC83FC97E0"" id=""BA1A844C01B74903954781232D5980DA""><id keyed_name=""SA006"" type=""Manufacturing Entity"">BA1A844C01B74903954781232D5980DA</id><itemtype>A46CE867356D43C8A3BC7FFC83FC97E0</itemtype></Item></mfg_line><item_nbr_base keyed_name=""605-5076-000"" type=""Part"">338283DC3371458F905E330976C77AB8</item_nbr_base></Item><Item type=""Concern"" typeId=""F1D2DE3EAFAB4B2B935D7061C49DF35B"" id=""E575F63FFA7746419D52134C3B0A5C4D""><classification>Production/Production Line</classification><id keyed_name=""C:059305"" type=""Concern"">E575F63FFA7746419D52134C3B0A5C4D</id><mfg_line keyed_name=""FA025"" type=""Manufacturing Entity""><Item type=""Manufacturing Entity"" typeId=""A46CE867356D43C8A3BC7FFC83FC97E0"" id=""20D641B68BC4490B9ABD10D21845FEFD""><id keyed_name=""FA025"" type=""Manufacturing Entity"">20D641B68BC4490B9ABD10D21845FEFD</id><itemtype>A46CE867356D43C8A3BC7FFC83FC97E0</itemtype></Item></mfg_line><item_nbr_base keyed_name=""905-3678-001"" type=""Part"">70255F00F1A943A7BC7B95354E9D531B</item_nbr_base></Item></Result></SOAP-ENV:Body></SOAP-ENV:Envelope>";
      var doc = new System.Xml.XmlDocument();
      doc.LoadXml(expected);
      var reader = new Pipes.Xml.XmlElementSource(doc).Pipe(new Pipes.Xml.XmlElementReader());
      using (var writer = new System.IO.StringWriter())
      {
        var settings = new XmlWriterSettings();
        settings.OmitXmlDeclaration = true;
        using (var xml = XmlTextWriter.Create(writer, settings))
        {
          reader.WriteTo(xml);
          xml.Flush();
        }
        Assert.AreEqual(expected, writer.ToString());
      }
    }
  }
}
